<template>
  <div class="">
     <el-card>
    <el-table :data="allRoles" border style="width: 100%">
      <el-table-column
        type="index"
        :lable="$t('msg.role.index')"
        width="120"
      ></el-table-column>
      <el-table-column
        :label="$t('msg.role.name')"
        width="120"
        prop="title"
      ></el-table-column>
      <el-table-column
        :label="$t('msg.role.desc')"
        prop="describe"
      ></el-table-column>
      <el-table-column :label="$t('msg.role.action')" width="200" #default="{ row }">
        <el-button type="primary" size="small" @click="onDistributePermissionClick(row)" v-permission="['distributePermission']">
          {{ $t('msg.role.assignPermissions') }}</el-button
        >
      </el-table-column>
    </el-table>
    </el-card>

    <DistributePermission v-model="distributePermissionVisible" :roleId="selectId" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { roleList } from '@/api/role'
import { watchSwitchLang } from '@/utils/i18n'
import DistributePermission from './components/DistributePermission.vue'

const allRoles = ref([])

const getRoleList = async () => {
  allRoles.value = await roleList()
}
getRoleList()
watchSwitchLang(getRoleList)

const distributePermissionVisible = ref(false)
const selectId = ref('')
const onDistributePermissionClick = (row) => {
  selectId.value = row.id
  distributePermissionVisible.value = true
}
</script>

<style lang="scss" scoped></style>
